use std::io::Read;
use std::ops::Mul;

pub mod jpeg_utils {
    use super::*;

    pub fn read_byte<T:Read>(reader: &mut T) -> u8 {
        let mut byte = [0u8;1];
        reader.read_exact(&mut byte).expect("Read A Byte Error");
        byte[0]
    }

    pub fn read_word<T:Read>(reader: &mut T) -> u16 {
        let mut word = [0u8;2];
        reader.read_exact(&mut word).expect("Read A Word Error");
        (word[0] as u16 ) << 8 | (word[1] as u16)
    }

    pub fn multi<T:Default+Mul<Output=T>+Copy,const N: usize>(left: [[T; N]; N], right: [T; N*N]) -> [[T; N]; N] {
        let mut ret: [[T; N]; N] = [[T::default(); N];N];
        for r in 0..N {
            for c in 0..N {
                ret[r][c] = left[r][c] * right[r*N + c];
            }
        }
        ret
    }
}
